﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace EnvCheck.View.Progress
{
    public class LoadingStateViewModel : BaseViewModel
    {
        private bool _isLoading;
        private string _loadingMessage;

        public bool IsLoading
        {
            get => _isLoading;
            set { _isLoading = value; OnPropertyChanged(nameof(IsLoading)); }
        }

        public string LoadingMessage
        {
            get => $"已加载{LoadingProgress}({Progress}/{this.Task})";
            set { _loadingMessage = value; OnPropertyChanged(nameof(LoadingMessage)); }
        }
        public int Task { get; set; } = 0;
        public int Progress { get; set; } = 0;
        public double LoadingProgress =>
            (this.Task == 0)
            ? 0
            : (1.0 * Progress / Task);

        public override void Receive(string appName, string version)
        {

        }
        public override void ReportProgress(int current, int total)
        {
            Progress = current;
            Task = total;
            OnPropertyChanged(nameof(LoadingProgress));
            OnPropertyChanged(nameof(LoadingMessage));
        }
    }
}
